package Demo;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class Test1 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
//        Callable<Integer> c = () -> {
//            int sum = 0;
//            for (int i = 1; i <= 100; i++) {
//                sum += i;
//            }
//            return sum;
//        };
        Callable<Integer> c = new Callable<>() {
            @Override
            public Integer call() {
                int sum = 0;
                for (int i = 1; i <= 100; i++) {
                    sum += i;
                }
                return sum;
            }
        };

        FutureTask<Integer> task = new FutureTask<>(c);
        Thread t = new Thread(task);
        t.start();
        int result = task.get();
        System.out.println(result);
    }
}
